/**
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
*
* MpmPMOStandardizationRecordService
* PMO标准化人选档案
*
* 修改纪录
* 2021-03-08 版本：1.0 fanzhiming 创建。
* @version 版本：1.0
* @author 作者：fanzhiming
* 创建日期：2021-03-08
*/
package com.topscomm.mpm.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.topscomm.basic.util.SQLAdapter;
import com.topscomm.mpm.pojo.MpmPMOStandardizationRecordEntity;
import com.topscomm.mpm.pojo.MpmProjectEntity;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.StringBufferProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.mpm.service.IMpmPMOStandardizationRecordService;
import com.topscomm.mpm.service.impl.auto.MpmPMOStandardizationRecordServiceAuto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(value = "mpmPMOStandardizationRecordService")
@Scope(value = "singleton")
public class MpmPMOStandardizationRecordService extends MpmPMOStandardizationRecordServiceAuto implements IMpmPMOStandardizationRecordService {
    @Autowired
    private MpmProjectService mpmProjectService;
    /**
     * @Title: queryPMOApproval
     * @description: 查询deptcommoncode对应的pmo审批人
     * @author: houyuhang
     * @date: 2023-02-07
     * @modify:
     */
    public List<MpmPMOStandardizationRecordEntity> queryPMOApproval(Map<String, Object> paraMap) {
        // 查询项目
        String projectcode = ConvertUtil.convertToString(paraMap.get("qry_projectcode"));
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle(" enabled = 1 and projectcode = '{0}' ", projectcode);
        MpmProjectEntity mpmProjectEntity = mpmProjectService.queryObjectByWhere(sql.toString());
        if (ObjectUtil.isEmpty(mpmProjectEntity)) {
            return new ArrayList<>();
        }
        // 根据deptcommoncode获取审批人信息
        String deptcommoncode = mpmProjectEntity.getDeptcommoncode();
        sql.clear();
        sql.appendSingle(" enabled = 1 and {0} like {1} ", SQLAdapter.concat(new String[] { "','", MpmPMOStandardizationRecordEntity.FieldChargedeptcommoncode, "','" }),
                SQLAdapter.concat(new String[] { "'%,'", deptcommoncode, "'%,'" }));
        return this.queryByWhere(sql.toString());
    }
}
